# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=asm-lsp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.10.0
pkgrel=2
pkgdesc="Language server for NASM/GAS/GO Assembly (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://crates.io/crates/asm-lsp'
msys2_repository_url='https://github.com/bergercookie/asm-lsp'
msys2_references=(
  'aur: asm-lsp'
  'purl: pkg:cargo/asm-lsp'
)
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-zstd")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=("https://github.com/bergercookie/asm-lsp/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "zstd-sys.tar.gz::https://crates.io/api/v1/crates/zstd-sys/2.0.13+zstd.1.5.6/download"
        "zstd-sys-remove-statik.patch")
sha256sums=('4755848aa7d88856be7e40d0930990b95b46c4593a53db3809d3ba7214d9d16d'
            '38ff0f21cfee8f97d94cef41359e0c89aa6113028ab0291aa8ca0038995a95aa'
            '48f4900ceb02d3aaf9a1020f33d56629156e96759f456c0e7ca18bfcf910767b')

prepare() {
  cd "${_realname}-${pkgver}"

  patch -d "../zstd-sys-2.0.13+zstd.1.5.6" -i "../zstd-sys-remove-statik.patch"
  cat >> Cargo.toml <<END

[patch.crates-io]
zstd-sys = { path = "../zstd-sys-2.0.13+zstd.1.5.6" }
END

  cargo update -p zstd-sys
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  export ZSTD_SYS_USE_PKG_CONFIG=1
  export RUSTFLAGS="${RUSTFLAGS/+crt-static/-crt-static}"
  cargo build --release --frozen --bin asm-lsp
}

package() {
  cd "${_realname}-${pkgver}"

  install -Dm755 target/release/asm-lsp.exe "${pkgdir}${MINGW_PREFIX}/bin/asm-lsp.exe"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
